<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>KTV选歌</title>
</head>
<body>
    
    <script>
        //定义两个曲库数组
        var allmusic = ['a','b','c','d','e','f'];
        var mymusic = [];

        //查看曲库方法
        function show(arr){
            var songStr = "";
            for(let i = 0;i<arr.length;i++){
                songStr += (i+1)+':'+arr[i]+"\n";
            }
            return songStr;
        }

        wh1:while(true){
            var str = prompt('1.新增歌曲\n2.查看我的曲库\n3.置顶歌曲\n4.删除歌曲\n5.退出系统')
            switch(str){
                case '1':
                    //查看曲库
                    var str = show(allmusic);
                    var num = prompt("选择添加歌曲：\n"+str)
                    //数据类型转换
                    var songNum =Number(num)-1
                    //插入歌曲到我的曲库
                    mymusic.push(allmusic[songNum])
                    alert('已成功添加歌曲')
                    break;

                case '2':
                    var mystr = show(mymusic);
                    var num = alert("我的曲库：\n"+mystr)
                    break;

                case '3':
                    var mystr = show(mymusic);
                    var str3=prompt("选择置顶歌曲：\n"+mystr)
                    mymusic.splice(0,0,mymusic[Number(str3)-1])
                    mymusic.splice(Number(str3),1)
                    alert('已成功置顶歌曲')
                    break;

                case '4':
                    var mystr = show(mymusic);
                    var str4=prompt("选择删除歌曲：\n"+mystr)
                    mymusic.splice(Number(str4)-1,1)
                    alert('已成功删除歌曲')
                    break;

                case '5':
                    break wh1;

                default:
                    alert('请输入合法的序号！')
                    break;
            }
        }
        window.close();

        

    </script>
</body>
</html>